package com.gjl.app.view.web.action;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.gjl.app.model.business.entity.User;
import com.gjl.app.model.business.entity.util.EntityManagerUtil;
import com.gjl.app.view.web.BaseAction;

public class RegisterAction  extends BaseAction{

	private static final long serialVersionUID = -6365793319559703227L;
	
	private String name;
	
	private String confirm;
	
	private String password;
	
	@Override
	public String execute() throws Exception {
		User user = new User();
		user.setDisplayName(confirm);
		user.setLoginName(name);
		user.setPassword(password);
		EntityManagerFactory  emf = EntityManagerUtil.getEntityManagerFactoryInstance();
		EntityManager entityManager = emf.createEntityManager();
		entityManager.persist(user);
		HttpServletRequest request = ServletActionContext.getRequest ();
		request.setAttribute("user", user);
		return super.execute();
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getConfirm() {
		return confirm;
	}

	public void setConfirm(String confirm) {
		this.confirm = confirm;
	}



	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
}
